namespace DotNetNuke.Security.Permissions
{
    using System;
    using System.Collections;
    using System.Reflection;

    public class FolderPermissionCollection : CollectionBase
    {
        public FolderPermissionCollection()
        {
        }

        public FolderPermissionCollection(ArrayList FolderPermissions)
        {
            int refIntHelperL0 = FolderPermissions.Count - 1;
            for (int i = 0; i <= refIntHelperL0; i++)
            {
                FolderPermissionInfo objFolderPerm = (FolderPermissionInfo) FolderPermissions[i];
                this.Add(objFolderPerm);
            }
        }

        public FolderPermissionCollection(ArrayList FolderPermissions, string FolderPath)
        {
            int refIntHelperL0 = FolderPermissions.Count - 1;
            for (int i = 0; i <= refIntHelperL0; i++)
            {
                FolderPermissionInfo objFolderPerm = (FolderPermissionInfo) FolderPermissions[i];
                if (objFolderPerm.FolderPath == FolderPath)
                {
                    this.Add(objFolderPerm);
                }
            }
        }

        public int Add(FolderPermissionInfo value)
        {
            return this.List.Add(value);
        }

        public bool CompareTo(FolderPermissionCollection objFolderPermissionCollection)
        {
            IEnumerator refObjectHelperL0=null;
            if (objFolderPermissionCollection.Count != this.Count)
            {
                return false;
            }
            this.InnerList.Sort(new CompareFolderPermissions());
            objFolderPermissionCollection.InnerList.Sort(new CompareFolderPermissions());
            try
            {
                refObjectHelperL0 = objFolderPermissionCollection.GetEnumerator();
                int i=0;

                while (refObjectHelperL0.MoveNext())
                {
                    FolderPermissionInfo objFolderPermission = (FolderPermissionInfo) refObjectHelperL0.Current;
                    if ((objFolderPermissionCollection[i].FolderPermissionID != this[i].FolderPermissionID) | (objFolderPermissionCollection[i].AllowAccess != this[i].AllowAccess))
                    {
                        return false;
                    }
                    i++;
                }
            }
            finally
            {
                if (refObjectHelperL0 is IDisposable)
                {
                    (refObjectHelperL0 as IDisposable).Dispose();
                }
            }
            return true;
        }

        public bool Contains(FolderPermissionInfo value)
        {
            return this.List.Contains(value);
        }

        public int IndexOf(FolderPermissionInfo value)
        {
            return this.List.IndexOf(value);
        }

        public void Insert(int index, FolderPermissionInfo value)
        {
            this.List.Insert(index, value);
        }

        public void Remove(FolderPermissionInfo value)
        {
            this.List.Remove(value);
        }

        public FolderPermissionInfo this[int index]
        {
            get
            {
                return (FolderPermissionInfo) this.List[index];
            }
            set
            {
                this.List[index] = value;
            }
        }
    }
}

